﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FinancePortal.Domain.Model;
using NHibernate.Mapping.ByCode;

namespace FinancePortal.Domain.Mapping
{
    public class AreaMapping : EntityMapping<Area>
    {
        public AreaMapping()
        {
            Property(x => x.Name, m =>
                {
                    m.Length(100);
                    m.NotNullable(true);
                }
            );

            Property(x => x.ParentAreaId, m =>
            {
                m.NotNullable(false);
                m.Column("ParentId");
            });

            Property(x => x.AreaClient, m =>
            {
                m.NotNullable(false);
                m.Column("AreaClient");
            });

            ManyToOne<Area>(x => x.ParentArea, m =>
            {
                //m.Cascade(Cascade.All);
                m.NotNullable(false);
                m.Column("ParentId");
                m.Insert(false);
                m.Update(false);
            });

            //Bag<Area>(x => x.ChildAreas,
            //    cp =>
            //    {
            //        //cp.Cascade(Cascade.None);
            //        cp.Lazy(CollectionLazy.NoLazy);
            //        cp.Inverse(true);
            //        cp.Key(k => k.Column("ParentId"));
            //    },
            //        cr =>
            //        {
            //            cr.OneToMany(om =>
            //                {
            //                    om.Class(typeof(Area));
            //                }
            //            );
            //        }
            //);

            //Bag<Activity>(x => x.Activities, 
            //    cp => 
            //    {
            //        cp.Key(k => k.Column("AreaId"));
            //    }, 
            //        cr => cr.OneToMany(x => x.Class(typeof(Activity))));

            //Bag<Resource>(x => x.Resources, 
            //    cp => 
            //    { 
            //        cp.Key(k => k.Column("ResourceId"));
            //    }, 
            //        cr => cr.OneToMany(x => x.Class(typeof(Resource))));
        }
    }
}
